<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
*/

/**
 * Description of Captcha
 *
 * @author chaporgin_a
 */
class VA_Form_FormElement_Captcha extends VA_Form_FormElement {
    protected $pathToCaptcha = '/components/com_electroforms/captchas/securimage_show.php';
    public function setCaptchaPath($path) {
        $this->pathToCaptcha = $path;
        return $this;
    }
    public function getCaptchaPath() {
        return $this->pathToCaptcha;
    }
    /**
     * Используется чтобы сделать заполнение капчи обязательным
     */
    public function getValidators() {
        $required = FALSE;
        $captcha = FALSE;
        foreach(parent::getValidators() as $validator) {
            if($validator instanceof VA_Form_Validator_Required) $required = TRUE;
            if($validator instanceof VA_Form_Validator_Captcha) $captcha = TRUE;
        }
        if(FALSE == $required)
            $this->addValidator(new VA_Form_Validator_Required());
        if(FALSE == $captcha) {
            $v= new VA_Form_Validator_Captcha();
            $v->init(array());
            $this->addValidator($v);
        }
        return parent::getValidators();
    }
    protected function setDefaultDecorators() {
        $this->decorators = array();
        $this->addDecorator('ViewHelper')
                ->addDecorator('Error')
                ->addDecorator('HtmlTag', array('tag'=>'div', 'classes'=>array('element', 'captcha')))
                ->addDecorator('Label', array('position' => VA_Form_Decorator_Label::PREPEND))
                ->addDecorator('HtmlTag', array('tag'=>'div', 'jQueryMark'=>'controlWrapper', 'classes'=>array('elementWrapper')));
    }
}

